/** 
 * FileName:     MapToObjectUtil.java 
 * @Description: TODO(用一句话描述该文件做什么) 
* All rights Reserved, Designed By hnkeystone 
 * Copyright:    Copyright(C) 2010-2011 
 * Company       坚磐科技 
 * @author:    冯辉 
 * @version    V1.0  
 * Createdate:         2017-3-18 下午2:04:33 
 * 
 * Modification  History: 
 * Date         Author        Version        Discription 
 * ----------------------------------------------------------------------------------- 
 * 2017-3-18       hnkeystone.com          1.0             1.0 
 * Why & What is modified: <修改原因描述> 
 */  
package com.fh.util;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.HashMap;
import java.util.Map;

/** 
 * @ClassName:     MapToObjectUtil 
 * @Description:TODO(这里用一句话描述这个类的作用) 
 * @author:    冯辉 
 * @date:        2017-3-18 下午2:04:33 
 *  
 */
public class MapToObjectUtil {
		  
	    public static Object mapToObject(Map<String, Object> map, Class<?> beanClass) throws Exception {    
	        if (map == null)  
	            return null;    
	  
	        Object obj = beanClass.newInstance();  
	  
	        Field[] fields = obj.getClass().getDeclaredFields();   
	        for (Field field : fields) {    
	            int mod = field.getModifiers();    
	            if(Modifier.isStatic(mod) || Modifier.isFinal(mod)){    
	                continue;    
	            }    
	  
	            field.setAccessible(true);    
	            field.set(obj, map.get(field.getName()));   
	        }   
	  
	        return obj;    
	    }    
	  
	    public static Map<String, Object> objectToMap(Object obj) throws Exception {    
	        if(obj == null){    
	            return null;    
	        }   
	  
	        Map<String, Object> map = new HashMap<String, Object>();    
	  
	        Field[] declaredFields = obj.getClass().getDeclaredFields();    
	        for (Field field : declaredFields) {    
	            field.setAccessible(true);  
	            map.put(field.getName(), field.get(obj));  
	        }    
	  
	        return map;  
	    }   
	}  
